package com.maikang.exammall.api;

import com.maikang.exammall.entity.GroupRegistry;
import com.maikang.exammall.entity.UserContext;
import com.maikang.exammall.entity.dto.ResponseDTO;
import com.maikang.exammall.service.GroupRegistryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@Log4j2
@RequestMapping("/api/group-registry")
@RequiredArgsConstructor
public class GroupRegistryController {
    private final GroupRegistryService service;

    @PostMapping
    public ResponseDTO<GroupRegistry> save(@Valid @RequestBody GroupRegistry entity) {
        entity.setUserId(UserContext.getUserId());
        return ResponseDTO.ok(service.save(entity));
    }

    @GetMapping("/count")
    public ResponseDTO<Long> count() {
        return ResponseDTO.ok(service.distinctCompany());
    }
}
